<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="HandheldFriendly" content="true" />
		<meta name="MobileOptimized" content="320" />
		<title>Hello H5+</title>
		<link rel="stylesheet" href="css/mui.css">
		<style type="text/css">
			#bcid {
				width: 100%;
				position: absolute;
				top: 0px;
				bottom: 44px;
				text-align: center;
			}

			.tip {
				color: #FFFFFF;
				font-weight: bold;
				text-shadow: 0px -1px #103E5C;
			}

			footer {
				width: 100%;
				height: 44px;
				position: absolute;
				bottom: 0px;
				line-height: 44px;
				text-align: center;
				color: #FFF;
			}

			.fbt {
				width: 50%;
				height: 100%;
				background-color: #007500;
				float: left;
			}

			.fbt:active {
				-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5);
				box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5);
			}
		</style>
	</head>

	<body style="background-color: #000000;">
		<div id="bcid">
			<div style="height:40%"></div>
			<p class="tip">...载入中...</p>
		</div>
	</body>
	<script src="js/mui.min.js"></script>
	<script type="text/javascript">
		var ws = null,
			wo = null;
		var scan = null,
			domready = false;
		// H5 plus事件处理
		function plusReady() {
			if(ws || !window.plus || !domready) {
				return;
			}

			var currentView = plus.webview.currentWebview(); // 获取 当前webview
			currentView.show('slide-in-right', 300); // 显示当前webview (方式,时间)
			plus.nativeUI.closeWaiting(); // 关闭系统 loading 等待框
			// 设置竖屏显示
			plus.screen.lockOrientation('portrait-primary');
			// 获取窗口对象
			ws = plus.webview.currentWebview();
			// 开始扫描
			ws.addEventListener('show', function() {
				scan = new plus.barcode.Barcode('bcid');
				scan.onmarked = onmarked;
				scan.start({
					vibrate: true,
					sound: 'default'
				});
			}, false);
			plus.key.addEventListener("backbutton", function() {
				var main = plus.webview.getWebviewById('main.html');
				mui.fire(main,'refresh');
			});
		}
		if(window.plus) {
			plusReady();
		} else {
			document.addEventListener('plusready', plusReady, false);
		}
		// 监听DOMContentLoaded事件
		document.addEventListener('DOMContentLoaded', function() {
			domready = true;
			plusReady();
		}, false);
		// 二维码扫描成功
		function onmarked(type, code, file) {
			code = code.replace(/\n/g, '');
			if(code.indexOf('http://') == 0 || code.indexOf('https://') == 0) {
				code = code.substring(code.indexOf('=') + 1)
			}
			//      plus.screen.lockOrientation('landscape-primary');
			var $contentW = localStorage.getItem('$contentW'),
				$menuLeftW = localStorage.getItem('$menuLeftW');
			var nwaiting = plus.nativeUI.showWaiting();
			webviewShow = plus.webview.create('scanResult.html', 'scanResult.html', {
				left: $menuLeftW,
				width: $contentW,
			}, {
				rid: code
			});
			ws.close();
		}
	</script>

</html>